"""
部门相关的Pydantic模型
"""
from typing import List, Optional
from pydantic import BaseModel, Field
from datetime import datetime


class DepartmentBase(BaseModel):
    """部门基础模型"""
    name: str = Field(..., description="部门名称", max_length=100)
    parent_id: Optional[str] = Field(None, description="父部门ID")
    manager_id: Optional[str] = Field(None, description="部门负责人ID")
    order: int = Field(0, description="排序")
    description: Optional[str] = Field(None, description="部门描述")


class DepartmentCreate(DepartmentBase):
    """创建部门模型"""
    pass


class DepartmentUpdate(BaseModel):
    """更新部门模型"""
    name: Optional[str] = Field(None, description="部门名称", max_length=100)
    parent_id: Optional[str] = Field(None, description="父部门ID")
    manager_id: Optional[str] = Field(None, description="部门负责人ID")
    order: Optional[int] = Field(None, description="排序")
    description: Optional[str] = Field(None, description="部门描述")


class DepartmentResponse(BaseModel):
    """部门响应模型"""
    id: str = Field(..., description="部门ID")
    name: str = Field(..., description="部门名称")
    parent_id: Optional[str] = Field(None, description="父部门ID")
    manager_id: Optional[str] = Field(None, description="部门负责人ID")
    manager_name: Optional[str] = Field(None, description="部门负责人姓名")
    order: int = Field(0, description="排序")
    description: Optional[str] = Field(None, description="部门描述")
    children: Optional[List['DepartmentResponse']] = Field(default_factory=list, description="子部门")
    user_count: int = Field(0, description="部门用户数量")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True


class DepartmentListResponse(BaseModel):
    """部门列表响应模型"""
    items: List[DepartmentResponse]
    total: int

